![]() |
NetBSD Documentation:NetBSD IPsec |
This page is developing, and we welcome any comments or suggestions.
Note that, however, kernel re-configuration is necessary to use IPsec. It is not turned on for default GENERIC kernel.
Userland code includes IPsec support where possible, by default, so no rebuild of userland is necessary even if you switch between kernel with IPsec, and without IPsec.
If you have pre-1.5 systems, your situation is as follows:
NOTE: We sometimes use the word "IP security" in more broader sense, like IP firewalls, packet filtering, and so forth.
IKE is actually optional, you can configure secret keys manually for AH/ESP. However, please understand it: you cannot use the same secret key forever. If you use the same secret key for a long period of time, your traffic become more and more likely to get compromised.
NOTE: security of IPsec protocols depend on the secrecy of secret keys. If secret keys are compromised, IPsec protocols can no longer be secure. Take caution about permission mode of configuration files, key database files, or whatever thay may lead to information leakage.
There two set of RFCs published; old IPsec suite starts from RFC1825, and new IPsec suite starts from RFC2401. Though NetBSD implements both, it is recommended to new IPsec suite.
userland programs IKE daemon ^ | AF_INET{,6} socket ^ | PF_KEY socket ========= | | =========================== | | ======== Kernel/user boundary | v | v transport layer, TCP/UDP key management table ^ | ^ | key information | | | | | v | v IP input/output logic <-------> AH/ESP/IPcomp logic ^ | | v Network drivers (ethernet)
[[transport mode]] my host ======== peer's host transport mode packets: [IP: me->peer] ESP payload <---------> encrypted [[tunnel mode]] (a) (b) (c) my host ---- my VPN gateway ======== peer's VPN gateway ---- peer's host tunnel mode packets on (a): [IP: me->peer] payload packets on (b): [IP: mygw->peergw] ESP [IP: me->peer] payload <------------------------> encrypted packets on (c): [IP: me->peer] payload
IPsec policy can be configured in per-packet, or per-socket manner:
options IPSEC options IPSEC_ESP
Userland tools include IPsec support by default, and no userland rebuild is necessary.
Additionally, you may want to install racoon and/or isakmpd.
#! /bin/sh # # packet will look like this: IPv4 ESP payload # the node is on 10.1.1.1, peer is on 20.1.1.1 setkey -c <<EOF add 10.1.1.1 20.1.1.1 esp 9876 -E 3des-cbc "hogehogehogehogehogehoge"; add 20.1.1.1 10.1.1.1 esp 10000 -E 3des-cbc "mogamogamogamogamogamoga"; spdadd 10.1.1.1 20.1.1.1 any -P out ipsec esp/transport//use; EOF
First two lines configure secret keys to be used by ESP. The decimal numbers appar as the fourth word are called SPI (security parameter index). The value will be attached to ESP packet, and it lets receiving side to lookup secret key from the packet. The number needs to be unique on a node.
The last line configures per-packet IPsec policy for the node. With the configuration, the node (10.1.1.1) to transmit packets to the peer (20.1.1.1) encrypted, whenever secret key is configured into the kernel. The configuration does not prohibit unencrypted packets from 20.1.1.1 to reach 10.1.1.1. If you would like to reject unencrypted packet, add the following line:
spdadd 10.1.1.1 20.1.1.1 any -P in ipsec esp/transport//require;
On the other end (20.1.1.1), the configuration will be like this. Note that there's no difference in "add" lines.
#! /bin/sh # # packet will look like this: IPv4 ESP payload # the node is on 20.1.1.1, peer is on 10.1.1.1 setkey -c <<EOF add 10.1.1.1 20.1.1.1 esp 9876 -E 3des-cbc "hogehogehogehogehogehoge"; add 20.1.1.1 10.1.1.1 esp 10000 -E 3des-cbc "mogamogamogamogamogamoga"; spdadd 20.1.1.1 10.1.1.1 any -P out ipsec esp/transport//use; EOF
The syntax for policy configuration is documented in ipsec_set_policy(3).
Try running tcpdump(8) to see the encrypted packets on the wire - they are encrypted, it is no longer possible to wiretap those packets.
The above exampe uses human-readable secret keys. However, use of human-readable secret key is discouraged by the specification (since it will have more chance to be compromised, than binary keys). You'd better use binary keys for real operation.
Key length is determined by algorithms. For 3des-cbc, the secret key MUST be 192 bits (= 24 bytes). If you specify shorter/longer key, you will get error from setkey(8).
If you wish to use other algorithms, the configuration is very similar. Here's an example with rijndael-cbc (also known as AES). rijndael-cbc takes 128, 192 or 256 bits of secret keys.
#! /bin/sh # # packet will look like this: IPv4 ESP payload # the node is on 10.1.1.1, peer is on 20.1.1.1 # rijndael-cbc with 128bit key setkey -c <<EOF add 10.1.1.1 20.1.1.1 esp 9876 -E rijndael-cbc "hogehogehogehoge"; add 20.1.1.1 10.1.1.1 esp 10000 -E rijndael-cbc "mogamogamogamoga"; spdadd 10.1.1.1 20.1.1.1 any -P out ipsec esp/transport//use; EOF
#! /bin/sh # # packet will look like this: IPv4 AH payload # the node is on 10.1.1.1, peer is on 20.1.1.1 setkey -c <<EOF add 10.1.1.1 20.1.1.1 ah 9877 -A hmac-md5 "hogehogehogehoge"; add 20.1.1.1 10.1.1.1 ah 10001 -A hmac-md5 "mogamogamogamoga"; spdadd 10.1.1.1 20.1.1.1 any -P out ipsec ah/transport//use; EOF
#! /bin/sh # # packet will look like this: IPv4 AH ESP payload # the node is on 10.1.1.1, peer is on 20.1.1.1 setkey -c <<EOF add 10.1.1.1 20.1.1.1 esp 9876 -E 3des-cbc "hogehogehogehogehogehoge"; add 20.1.1.1 10.1.1.1 esp 10000 -E 3des-cbc "mogamogamogamogamogamoga"; add 10.1.1.1 20.1.1.1 ah 9877 -A hmac-md5 "hogehogehogehoge"; add 20.1.1.1 10.1.1.1 ah 10001 -A hmac-md5 "mogamogamogamoga"; spdadd 10.1.1.1 20.1.1.1 any -P out ipsec esp/transport//use ah/transport//use; EOF
((( 10.0.1.0/24 ))) VPN'ed network |10.0.1.1 gateway 1 |20.0.0.1 |IPsec tunel |20.0.0.2 gateway 2 |10.0.2.1 ((( 10.0.2.0/24 ))) VPN'ed network
#! /bin/sh # # Note that routing should be set up in advance, i.e. for this example: # route -n add -net 10.0.2.0 10.0.2.1 # route -n add 10.0.2.1 10.0.1.1 # packet will look like this: IPv4 ESP IPv4 payload # the node is on 10.0.1.1/20.0.0.1, peer is on 10.0.2.1/20.0.0.2 setkey -c <<EOF add 20.0.0.1 20.0.0.2 esp 13245 -E blowfish-cbc "blowfishtest.001" ; add 20.0.0.2 20.0.0.1 esp 13246 -E blowfish-cbc "blowfishtest.002" ; spdadd 10.0.1.0/24 10.0.2.0/24 any -P out ipsec esp/tunnel/20.0.0.1-20.0.0.2/req uire ; spdadd 10.0.2.0/24 10.0.1.0/24 any -P in ipsec esp/tunnel/20.0.0.2-20.0.0.1/requ EOF(contributed by Per Harald Myrvang)
Please follow the steps carefully. Run tcpdump(8) to check how the packets are exchanged between two nodes. Statistics by "netstat -sn" is also useful to know how kernel IPsec portion is working.
A# setkey -c spdadd A B any -P out ipsec esp/transport//require; spdadd B A any -P in ipsec esp/transport//require; ^D
B# setkey -c spdadd B A any -P out ipsec esp/transport//require; spdadd A B any -P in ipsec esp/transport//require; ^D
A# cat >/etc/racoon/psk.txt B spamspamspam ^D A# chmod 600 /etc/racoon/psk.txt B# cat >/etc/racoon/psk.txt A spamspamspam ^D B# chmod 600 /etc/racoon/psk.txt
# /usr/pkg/sbin/racoon -f /etc/racoon/racoon.conf -d 0xffffffff
A# ping -n B (with some delay, you will start seeing replies) ^C A# setkey -D (you will see keys exchanged by racoon)
A# setkey -c spdadd A[110] A tcp -P out none; spdadd A A[110] tcp -P in none; spdadd A[110] 0.0.0.0/0 tcp -P out ipsec ah/transport//require; spdadd 0.0.0.0/0 A[110] tcp -P in ipsec ah/transport//require; ^D B# setkey -c spdadd B A[110] tcp -P out ipsec ah/transport//require; spdadd A[110] B tcp -P in ipsec ah/transport//require; ^D
/sbin/setkey -c < /etc/ipsec.conf
Interoperability with other implementation has been confirmed in various occasions. /sys/netinet6/IMPLEMENTATION includes list of implementations which we have confirmed interoperability in the past. Note that, however, it is possible for both sides to change the code after interoperability tests, and it is possible that they no longer interoperate. It is also possible that NetBSD device and peer's device interoperate in certain configuration only.
If you try to configure NetBSD device with other implementation, please note that IPsec specifications/implementations have too many knobs to play with. You need to configure your NetBSD device with peer's device exactly the same to make them interoperate.
We have RFC2367 PF_KEY API for manipulating secret key database in the kernel. Basic portion of this API is available on other UNIX-based IPsec stacks as well, and may be compatible to certain degree (for example, OpenBSD implements PF_KEY API as well). KAME IPsec stack extends this in certain way, just like other parties do. Extended portion is not compatible with other (non-KAME) IPsec stacks.
There is no document that specifies IPsec policy management API. Therefore, we can expect no compatibility with (non-KAME) IPsec stacks in IPsec policy management API.
There is no standard for configuration file syntax. You will need to convert them if you would like to copy configuration from/to non-NetBSD IPsec devices.
Since NetBSD and FreeBSD share IPsec codebase from the same origin (KAME), there is a good chance for API compatibility. Note that, however, there are differences in NetBSD IPsec code and FreeBSD IPsec code, since they merged in KAME code of different date. As of writing, normal userland applications do not need to worry about the difference:
During NetBSD-current development between NetBSD 1.4 to NetBSD 1.5, we have imported KAME IPsec portion three times. Those imports contain backward-incompatible changes in the API. Please make sure to use the latest code, if you are on NetBSD-current between 1.4 and 1.5. Once NetBSD 1.5 is get shipped, we will provide complete binary compatibility, or API version number check, to the API present in NetBSD 1.5.
|
|